package com.hand.demo.api.controller.v1;

import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.ApiOperation;
import org.hzero.boot.message.MessageClient;
import org.hzero.boot.message.entity.Message;
import org.hzero.boot.message.entity.Receiver;
import org.hzero.core.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.Map;

@RestController("MessageController.v1")
@RequestMapping("/v1/xzy-demo")
public class MessageController extends BaseController {
    @Autowired
    private MessageClient messageClient;

    @ApiOperation(value = "指定接收人列表发送站内消息")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
    @PostMapping("/send-message")
    public Message sendWebMessage(long tenantId,
                                  String messageTemplateCode,
                                  long receiverMan,
                                  Map<String, String> args) {
        // 指定接收人的用户ID，以及目标租户ID
        Receiver receiver = new Receiver().setUserId(receiverMan).setTargetUserTenantId(receiverMan);
        return messageClient.sendWebMessage(tenantId, messageTemplateCode, Collections.singletonList(receiver), args);
    }

}
